package com.yale.spring.cloud.gateway.config;

import com.yale.spring.cloud.gateway.filter.WebFilter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author yale
 */
@Configuration
public class RoutConfiguration {

    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder,  WebFilter webFilter) {
        return builder.routes()
                .route(p ->
                        p.path("/api/user/**")
                                .uri("lb://user-service")
                                .id("user-service"))
                .route(p ->
                        p.path("/api/email/**")
                                .uri("lb://email-service")
                                .id("email-service"))
                .route(p ->
                        p.path("/api/code/**")
                                .uri("lb://code-service")
                                .id("code-service"))
                .build();
    }
}
